package Correct;

import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import Frame.FCTip;

public class Correct extends JFrame {
	private CorrectFunction correctFunction = new CorrectFunction();

	public Correct() {
		setTitle("修正工具"); // 设置窗口标题
		setIconImage(Toolkit.getDefaultToolkit().createImage("./image/GongZuoTai1.png")); // 设置窗口图标
		setBounds(0, 0, 500, 380); // 设置窗口大小和位置
		setResizable(false); // 禁止调整窗口大小
		setLocationRelativeTo(null); // 居中显示窗口
		setLayout(null); // 使用绝对布局

		// 添加窗口关闭事件监听器，当用户点击关闭按钮时退出程序
		addWindowListener(new WindowListener() {
			@Override
			public void windowClosing(WindowEvent e) {
				System.exit(0); // 关闭窗口并退出程序
			}
			// 其他窗口事件未使用，保持默认实现
			@Override
			public void windowOpened(WindowEvent e) {
			}

			@Override
			public void windowIconified(WindowEvent e) {
			}

			@Override
			public void windowDeiconified(WindowEvent e) {
			}

			@Override
			public void windowDeactivated(WindowEvent e) {
			}

			@Override
			public void windowClosed(WindowEvent e) {
			}

			@Override
			public void windowActivated(WindowEvent e) {
			}
		});

		JLabel selectt = new JLabel("选择功能"); // 功能选择标签
		selectt.setBounds(10, 10, 80, 20);
		this.add(selectt);

		JComboBox<String> select = new JComboBox<String>(); // 功能选择下拉框
		select.addItem("test"); // 测试功能
		select.addItem("修复地图实体数据"); // 修复地图实体数据功能
		select.setBounds(80, 10, 400, 20);
		this.add(select);

		JScrollPane info = new JScrollPane(); // 文本信息滚动面板
		info.setBounds(10, 40, 470, 270);
		info.setBorder(BorderFactory.createLineBorder(Color.black)); // 设置边框颜色
		info.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); // 垂直滚动条按需显示
		this.add(info);

		JTextArea infoo = new JTextArea(); // 显示操作日志的文本区域
		infoo.append("--------------------\nFC游戏编辑器数据修复工具 v1.0\n请先选择修复功能，然后点击开始。\n--------------------\n");
		infoo.setBounds(0, 0, info.getWidth(), info.getHeight());
		info.setViewportView(infoo);

		JButton ok = new JButton("开始"); // 开始按钮
		ok.setBounds(400, 320, 80, 20);
		this.add(ok);

		// 按钮点击事件：根据选择的功能执行相应的修复操作
		ok.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (correctFunction.startcorrect(infoo, select.getSelectedIndex())) // 调用修复方法
					new FCTip("数据修复", "修复完成!"); // 提示修复成功
				else
					new FCTip("数据修复", "修复失败!"); // 提示修复失败
			}
		});

		setVisible(true); // 显示窗口
	}
}